home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
basic
/
UDP_Chat.lha
/
UDPChat
/
Lag problems in Net games
next >
Wrap
Text File
|
1999-03-29
|
22KB
|
457 lines
On 11-Apr-98, Paul Burkey wrote:
>Hi Dave,
>> Now that's all fine, I can do most of the TCP/IP stuff pretty
>> easily, but I have some other problems. Does anyone know of the best
>way
>> to do 8 seperate players playing on the same game over the internet.
>Like
>> how would you linkup 8 players...all to one player, or all in a
chain.
>With more than 4 players I'd avoid the chain idea. That is unless you
>can deal with large amounts of lag and you don't need to be fully
>synchronised. The 1 server many clients idea is the safest and easiest
>system to deal with but ALWAYS the best way.
First check out Paul's netpage:
<http://www.sneech.demon.co.uk/netlink.html>
It's got some links to pages with the problems you're likely to come
up against. I've been researching this for the last 6 or so months (with
some help from Paul), because I want to put multiplayer internet support
into a similar type of game as yours- a fast reaction arcade game. The
big problem as far as I can see is the lag you get from when one
computer sends a move, and the other machine receives it. This is worse
on a 2D game because you'll see if something's a few pixels out- on a 3D
game you'll never really notice anything is out, unless the lag is
terrible. You have to do everything to cut down the lag time
>> it depends on how much data I'm gonna have to send to every player.
>> And that's the second problem, do I just send co-ordinates of
>> every player, and say ever players bullets, and any objects
>> they pick up, or do I send just the players action, and work out the
>> outcome of that action and then reply with a message to say that it
>worked
>> okay.
>As always it's not easy to give any firm directions with this kind of
>stuff. You may have good reasons why you need to keep things
>synchronised
>or you may have a design that can cope with large amounts of lag. It
>depends on the gameplay really. I'd probably suggest using the I/O
>method where instead of sending coordinates or players, bullets
>and whatever else. You just send the players inputs. So if player 1
>moves forwards you send this. If he doesn't move anywhere then you
>don't send anything.
Yes, I think this is the only way you could have it work for lots of
players- otherwise you'd physically run out of bandwidth (you wouldn't
be able to get enough information through the modem in a given time).
Instead of sending out each new pixel position of an object, you just
send out differences in speed, acceleration and direction with a
time-stamp. As all machines are time-synced at the start you can then
adjust the Avatar (copy of your player etc on another machine) to the
exact position the original is on-screen (using simple physics), because
you know what speed and direction it was traveling at a certain point in
time. Your characters actually are in sync more than the position method
which would always be behind by whatever the lag was. This is how
Quake/XWing etc do it.
So if a monsta is traveling down a corridor, you can ignore it until
it goes down a different angled corridor, then you send this info out to
the other machines. You just have to have one machine only, responsible
for each object onscreen- so I was thinking of using the Server to say
which machine is responsible for which monsta etc (even though I'm using
peer-to-peer, I've got a Server to log in to), and other objects like
bombs, doors, etc could be controlled this way as well. This solves your
problem about having two players in one space, as only one machine makes
the decisions for each object. You might get visual glitches like
shooting a player and it misses them when it should have hit, because
the actual player was really a few pixels off, but if the lag times can
be kept down this shouldn't be much of a problem.
A point raised on one of the web pages, was the problem that could be
caused by lag. Say for example, a monsta has AI that makes it chase a
player on line-of-sight. If a player changes direction just before an
intersection say, and a monsta is in line-of-sight of that intersection
eg:
-------------+-+--------------
P-> P- player
-------------+ +--------------
| |
| |
-------------+ +--------------
M-> M- monsta
-------------+-+--------------
If the lag to one machine is greater than another, you could get the
situation of the monsta going in two different directions on the two
machines. On the machine with the faster connection the Avatar has
turned back (as the human player has), so the monsta carries on along
the way it was going; on the machine with the slightly slower connection
the Avatar goes a few pixels into the corridor before turning back, and
the monsta sees it and changes direction and chases it down the
corridor. Once the monsta changes course on one machine, the courses of
the two monstas will continue to diverge :-/ (sort of like that old (I
think it was H.G Wells') sci-fi story about the guy who goes back in
time and accidentally kills a butterfly :)
If you have the one machine only making decisions for an object, it
solves this problem.
>> Like if 4 players each tried to enter the same square, and only 1
>> could...which one would it be, and how would I tell all the others
>which
>> one it was. I hope that hasn't confused everyone...cos it's confused
>me.
>This is where the 'one server many clients' idea can make life very
>easy. The following is just a rough plan, I'm making most of it up
>as I go along so feel free to pick the ideas appart until we can
>agree on a solution. Also lets understand that this idea would work
>for some gams and not for others...
>Lets imagine you have 20 players. Each player would have a unique
>number eg 1,2,3..20. Now imagine that each player has to send
>commands to the server and wait for the command to arive back before
>the command can be executed. A command may be something like 'shoot',
>'move forwards', 'move backwards' or whatever. Any commands player
>1 sends to the server will be mirrored to all other players as well
>as himself. Now lets imagine that the server is setup so that it
>will take incomming commands for 1/10 of a second and then send
>them all out. If no commands are taken then the server will send a
>'no commands' message to everyone. The game would be setup to
>gather these commands and sort them into order. So all player 1
>commands would be executed first, then player 2 and so on. A better
>solution would be for the server to attach a timestamp to each
>command as it arives. Then a batch of commands are sent out and
>these can then be sorted into the same order as thy arived on
>the server.
>Some extra error checking should be used in this example but theres
>no need to go into too much detail here.
>To get back to your question.. Each player would move towards
>this same square at the same time. So the 'move to square'
>command is sent to the server and then the server sends these
>commands to the players. All players will attempt to execute
>the commands in the same order so player 1 will be first and
>then player 2. Player 2 can't move into the square because
>player 1 beat him to it.
This is ok as long as it runs fast enough for your game- for an
arcade type game I think it might run too slow (as you have to send the
message to the Server and then back to the Client (which could double
lag times). I'm using Peer-to-Peer (every machine sends its messages to
all machines), which by-passes the Server.
In Quake, I think they have a max of 8 players peer-to-peer, and up
to 16 going through a dedicated Server (as in Paul's way, but only to
pass messages on, not to do any logic). But these Servers are rather
powerful with a fast direct net connections.
This is all theory at the moment as I haven't had time to put the
code into a small test game to see what works :-/
Also am using UDP instead of TCP which is much faster but has no
error checking. I've done a little chat program using UDP which checks
wether packets have arrived at their target or not, and has a basic
log-in Server- but all message